var MachineDynamicTable = function () {
  var template = /*html*/ `
    <div>
      <el-table fit stripe border ref="machineDynamicTable" :data="dynamics" :height="hasScroll?'parent':undefined">
        <el-table-column :resizable="false" prop="equipmentName" label="设备名称" :auto-width="true" min-width="70px">
        </el-table-column>
        <el-table-column :resizable="false" prop="equipmentNo" label="设备编号" :auto-width="true" min-width="70px">
        </el-table-column>
        <el-table-column :resizable="false" prop="machingCount" label="加工数量" min-width="100px">
        </el-table-column>
        <el-table-column :resizable="false" label="待机时间" :auto-width="true" min-width="70px">
          <template slot-scope="scope">
            <span v-if="scope.row.waitTime!==''">{{getTimeStr(scope.row.waitTime)}}</span>
          </template>
        </el-table-column>
        <el-table-column :resizable="false" label="加工时间" :auto-width="true" min-width="70px">
          <template slot-scope="scope">
            <span v-if="scope.row.machingTime!==''">{{getTimeStr(scope.row.machingTime)}}</span>
          </template>
        </el-table-column>
        <el-table-column :resizable="false" label="关机时间" :auto-width="true" min-width="70px">
          <template slot-scope="scope">
            <span v-if="scope.row.offTime!==''">{{getTimeStr(scope.row.offTime)}}</span>
          </template>
        </el-table-column>
        <el-table-column :resizable="false" label="每日平均工作时间" :auto-width="true" min-width="135px">
        <template slot-scope="scope">
          <span v-if="!isNaN(scope.row.dayMeanTime)">{{getTimeStr(scope.row.dayMeanTime)}}</span>
          <span v-else>未确定查询时间区间</span>
        </template>
        </el-table-column>
        <el-table-column :resizable="false" label="日标准工作时间" :auto-width="true" min-width="130px">
          <template slot-scope="scope">
            <span v-if="scope.row.dayNormTime!==''">{{parseInt(scope.row.dayNormTime)}}小时</span>
          </template>
        </el-table-column>
        <el-table-column :resizable="false" label="利用率" min-width="80px">
          <template slot-scope="scope">
            <span v-if="scope.row.usedRate!==''">{{scope.row.usedRate}}%</span>
          </template>
        </el-table-column>
        <el-table-column :resizable="false" prop="unqualifiedCount" label="不良数" min-width="90px">
        </el-table-column>
        <el-table-column :resizable="false" label="合格率" min-width="80px">
          <template slot-scope="scope">
            <span v-if="scope.row.qualifiedRate!==''">{{scope.row.qualifiedRate}}%</span>
          </template>
        </el-table-column>
      </el-table>
    </div>
  `;

  return {
    props: {
      dynamics: {
        type: Array,
        default: []
      },
      hasScroll: {
        type: Boolean,
        default: false
      }
    },
    data: function () {
      return {};
    },
    methods: {
      getTimeStr: function (time) {
        time = time * 60 * 1000;
        var timeMoment = moment.duration(time);
        var day = Math.floor(timeMoment.asDays());
        var hour = timeMoment.hours();
        var minute = timeMoment.minutes();
        var str = '';
        if (day !== 0) {
          str += `${day}天`;
        }
        if (hour !== 0) {
          str += `${hour}小时`;
        }
        str += `${minute}分钟`;
        return str;
      }
    },
    template: template
  };
}();